package com.example.q_kang.hhh.setting;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.q_kang.hhh.R;
import com.hjq.toast.ToastUtils;
import com.sskj.base.MVPActivity;
import com.sskj.base.api.SpConfig;
import com.sskj.base.base.App;
import com.sskj.base.utils.CheckUtil;
import com.sskj.base.utils.ClickUtil;
import com.sskj.base.utils.SPUtils;
import com.sskj.base.view.ToolBarLayout;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author Hey
 * Create at  2019/04/10
 */
public class BindingAlipayActivity extends MVPActivity<BindingAlipayPresenter> {
    @BindView(R.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.et_alipay)
    EditText etAlipay;
    @BindView(R.id.iv_QRcode)
    ImageView ivQRcode;
    @BindView(R.id.et_code)
    EditText etCode;
    @BindView(R.id.tv_get_code)
    TextView tvGetCode;
    @BindView(R.id.btn_submit)
    Button btnSubmit;

    @Override
    public int getLayoutId() {
        return R.layout.activity_binding_alipay;
    }

    @Override
    public BindingAlipayPresenter getPresenter() {
        return new BindingAlipayPresenter();
    }

    @Override
    public void initView() {
        toolbar.setLeftButtonOnClickListener(view -> finish());
        ClickUtil.click(300, tvGetCode, view ->
                mPresenter.sendCode((String) SPUtils.get(App.INSTANCE, SpConfig.MOBILE, "")));
        ClickUtil.click(300, btnSubmit, new ClickUtil.Click() {
            @Override
            public void click(View view) {
                if (TextUtils.isEmpty(etName.getText().toString())) {
                    ToastUtils.show(App.INSTANCE.getString(R.string.appJavaBindingAlipayActivity2));
                    return;
                }
                if (TextUtils.isEmpty(etAlipay.getText().toString())) {
                    ToastUtils.show(App.INSTANCE.getString(R.string.appJavaBindingAlipayActivity3));
                    return;
                }
                if (TextUtils.isEmpty(etCode.getText().toString())) {
                    ToastUtils.show(App.INSTANCE.getString(R.string.appJavaBindingAlipayActivity4));
                    return;
                }
                mPresenter.bindAliPay(etName.getText().toString(),
                        etAlipay.getText().toString(),
                        etCode.getText().toString());
            }
        });
    }

    @Override
    public void initData() {

    }

    public static void start(Context context) {
        Intent intent = new Intent(context, BindingAlipayActivity.class);
        context.startActivity(intent);
    }

    public void sendCodeSuccess() {
        startTimeDown(tvGetCode);
    }

    public void bindAliPySuccess() {
        finish();
    }
}
